package Offer2017;

/**
 * 不用加减乘除做加法
 * Created by 雷文康 on 2018/1/6.
 */
public class Test47 {
    public static void main(String[] args) {
        System.out.println(sum(-8, -2));
    }
    public static int sum(int num1, int num2) {
        //异或相当于加法，只是没有进位
        int sum;
        int carry;
        do {
            sum = num1 ^ num2;
            carry = (num1 & num2) << 1;
            num1 = sum;
            num2 = carry;
        } while (carry != 0);
        return num1;
    }
}
